﻿/*
 * Сделано в SharpDevelop.
 * Пользователь: Кулик
 * Дата: 29.03.2011
 * Время: 16:57
 * 
 * Для изменения этого шаблона используйте Сервис | Настройка | Кодирование | Правка стандартных заголовков.
 */
using System;
using System.Collections.Generic;

namespace Video.Mov
{
	public class Atom{
		
		public Atom(){
			Type = new char[4];
			Size = 0;
			Child = new List<Atom>();
		}
		
		public Atom(Atom atom):this(){
			//Atom();
			//Type = new char[4];
			Size = atom.Size;
			Type = atom.Type;
		}
		
		public uint Size;
		public char[] Type; //4 byte
		public uint NumberOfEntries;
		public List<Atom> Child;
		public byte[] Data;
		public byte Version;
		public byte[] Flags = new byte[3];
	}
	
	public class QTAtom: Atom{
		//Container header
		public byte[] Resreved; //always 10 byte
		public ushort LockCount; //always 0
		
		public uint AtomID;
		public ushort Reserved; 
		public ushort ChildCount; 
		public uint Reserved2; 
	}
	
	public class FtypAtom:Atom{
		public FtypAtom(Atom atom){
			Size = atom.Size;
			Type = atom.Type;
		}
		
		public char[] MajorBrand = new char[4];
		public uint Ver;
		public char[] CompatibleBand1 = new char[4];
		public char[] CompatibleBand2 = new char[4];
	}
	/// <summary>
	/// pnot
	/// </summary>
	public class PreviewAtom: Atom{
		public int ModificationDate;
		public short VersionNumber;
		public int AtomType;
		public short AtomIndex;
	}

	/// <summary>
	/// obid
	/// </summary>
	public class ObjectIDAtom:Atom{
		int ObjectID;
	}
	
	/// <summary>
	///   ty
	/// </summary>
	public class InputTypeAtom:Atom{
		int InputType;
	}
	
//	/// <summary>
//	/// udta
//	/// </summary>
//	public struct UserDataAtom:Atom{
//		public UserDataListAtom userDataList;
//	}
//	
//	/// <summary>
//	/// udta
//	/// </summary>
//	public struct UserDataListAtom:Atom{
//		Atom UserData;
//	}
	

//	/// <summary>
//	/// minf
//	/// </summary>
//	public struct BaseMediaInformationAtom:Atom{
//		public BaseMediaInformationHeaderAtom baseMediaInformationHeaderAtom;
//		public BaseMediaInfoAtom baseMediaInfoAtom;
//	}
//	
//	/// <summary>
//	/// gmhd
//	/// </summary>
//	public struct BaseMediaInformationHeaderAtom:Atom{
//		
//	}
	
	/// <summary>
	/// gmin
	/// </summary>
	public class BaseMediaInfoAtom:Atom{
		short GraphicsMode;
		byte[] Opcolor = new byte[6];
		short Balance;
		short Reserved;
	}
	
	/// <summary>
	/// dinf
	/// </summary>
	public class DataInformationAtom:Atom{
		
	}
	
//	/// <summary>
//	/// dref
//	/// </summary>
//	public struct DataReferenceAtom:Atom{
//		byte Version;
//		byte[] Flags = new byte[3];
//		int NumberOfEntries;
//		List<DataReference> dataReference;
//	}
//	
//	/// <summary>
//	/// alis, rsrc
//	/// </summary>
//	public struct DataReference:Atom{
//		byte Version;
//		byte[] Flags = new byte[3];
//		object Data;
//	}
	
		
	/// <summary>
	/// ctab
	/// </summary>
	public class ColorTableAtom:Atom{
		public int ColorTableSeed;
		public short ColorTableFlag;
		public short ColorTableSize;
		public List<byte> ColorArray;
	}
	
			
	/// <summary>
	/// Description of Struct.
	/// </summary>
	public struct MOVIentry
	{
		public ushort size;
		public ulong pos;
		public ushort samplesInChunk;
		public ushort entries;
		public short  cts;
		public ulong dts;
		public uint   flags;
	}
	
	public struct HintSample {
		public byte[] data;
		public short size;
		public short sample_number;
		public short offset;
		public short own_data;
	}

	public  struct HintSampleQueue{
		public short size;
		public short len;
		HintSample samples;
	}

	//MOVIndex
	public struct MOVTrack {
		public short         mode;
		public short         entry;
		public uint    timescale;
		public ulong    time;
		public long     trackDuration;
		public int        sampleCount;
		public int        sampleSize;
		public short         hasKeyframes;
		
		public uint    flags;
		public short         language;
		public short         trackID;
		public short         tag; ///< stsd fourcc
		//public AVCodecContext enc;

		public short         vosLen;
		public byte[]     vosData;
		public MOVIentry[]   cluster;
		public short         audio_vbr;
		public short         height; ///< active picture (w/o VBI) height for D-10/IMX
		public uint    tref_tag;
		public short         tref_id; ///< trackID of the referenced track

		public short         hint_track;   ///< the track that hints this track, -1 if no hint track is set
		public short         src_track;    ///< the track that this hint track describes
		//public AVFormatContext rtp_ctx; ///< the format context for the hinting rtp muxer
		public uint    prev_rtp_ts;
		public long     cur_rtp_ts_unwrapped;
		public uint    max_packet_size;

		public HintSampleQueue sample_queue;
	}

	public struct MOVMuxContext {
		public short     mode;
		public long time;
		public short     nb_streams;
		public short     chapter_track; ///< qt chapter track number
		public long mdat_pos;
		public ulong mdat_size;
		public MOVTrack tracks;
	}
}
